const communityModel = require('../models/CommunityModel')
const fs = require('fs')
let communityController = {
    //文章渲染
    get_index:function(req, res){
        communityModel.articlelist_show(req, res)
    },
    //详细内容渲染
    post_show:function(req, res) {
        communityModel.article_show(req, res)
    },
    //发布文章
    post_add:function(req, res) {
        communityModel.article_add(req, res)
    },
    // get_agreeshow:function (req, res) {
    //     communityModel.thumbs_show(req, res)
    // },
    //点赞功能
    post_agree:function (req, res) {
        communityModel.thumbs_up(req,res)
    },
    /**
     * 发布文章图片暂存
     * @param {*} req 
     * @param {*} res 
     */
    post_articp: async function (req, res) {
        let pubUrl = './public/cacheimg/';

        console.log( req.files.file.name, req.files);
        await fs.createReadStream(req.files.file.path).pipe(fs.createWriteStream(pubUrl + req.files.file.name))

        res.send({
            code: 200,
            add: req.files.file.name
        })
        communityModel.thumbs_up(req, res)
    },
    //评论功能
    post_comment:function (req, res) {
        communityModel.release_comments(req, res);
    },
    //评论渲染
    get_showcomments:function (req, res) {
        communityModel.show_comments(req, res)
    }
}
module.exports = communityController